<?php

namespace App\Models\Wanggui;

use App\Models\BaseModel;
use App\Models\Common\ResourcesModel;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;

class CustomerDepartmentFollowUpRecordModel extends BaseModel
{
    use HasFactory;

    protected $table = 'customer_department_follow_up_record';

    protected $fillable = [
        'taskId',
        'type',
        'method',
        'content',
        'createdAt',
        'createdByUid',
        'updatedAt',
        'updatedByUid',
    ];

    /**
     * 跟进类型
     */
    const TYPE_PARTY_A  = 0;
    const TYPE_BUNK     = 1;
    const TYPE_CUSTOMER = 2;

    const TYPE_MAPPING = [
        self::TYPE_PARTY_A  => '跟进甲方',
        self::TYPE_BUNK     => '跟进铺位',
        self::TYPE_CUSTOMER => '跟进加盟商',
    ];


    /**
     * 跟进方式
     */
    const METHOD_MOBILE = 0;
    const METHOD_TEXT   = 1;
    const METHOD_SCENE  = 2;

    const METHOD_MAPPING = [
        self::METHOD_MOBILE => '电话跟进',
        self::METHOD_TEXT   => '线上跟进',
        self::METHOD_SCENE  => '线下跟进',
    ];


    /**
     * 关联甲方
     * @return HasOne
     */
    public function kpPartyRel(): HasOne
    {
        return $this->hasOne(CustomerDepartmentKpPartyRecordModel::class, 'id', 'kpPartyId');
    }


    /**
     * 关联资源表
     * @return HasMany
     */
    public function resourceRel(): HasMany
    {
        return $this->hasMany(ResourcesModel::class, 'businessId', 'id')->where('module', ResourcesModel::MODULE_TYPE_COMMUNICATE_RECORD)->where('business', ResourcesModel::BUSINESS_COMMUNICATE_RECORD);
    }


    /**
     * 关联线索
     * @return HasMany
     */
    public function clueRel(): HasMany
    {
        return $this->hasMany(CustomerDepartmentClueRecordModel::class, 'id', 'clueId');
    }


    /**
     * 关联线索
     * @return HasOne
     */
    public function taskRel(): HasOne
    {
        return $this->hasOne(CustomerDepartmentTaskModel::class, 'id', 'taskId');
    }

}
